﻿using Microsoft.Extensions.DependencyInjection.Extensions;
using Sino.CapacityCloud.Infrastructure.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Microsoft.Extensions.DependencyInjection
{

    public static class AzureEventBusBuilderExtensions
    {

        public static void AddEventBus<TEventBus>(this IServiceCollection services, Action<EventBusOptions> setupAction) where TEventBus : class, IEventBus
        {
            if (services == null)
            {
                throw new ArgumentNullException("services");
            }
            if (setupAction == null)
            {
                throw new ArgumentNullException("setupAction");
            }
            AddEventBus<TEventBus>(services);
            if (setupAction != null)
            {
                services.Configure(setupAction);
            }
        }

        public static void AddEventBus<TEventBus>(this IServiceCollection services) where TEventBus : class, IEventBus
        {
            services.TryAddEnumerable(ServiceDescriptor.Singleton<IEventBus, TEventBus>());
        }

    }

}